import AbilityStage from '@ohos.app.ability.AbilityStage';
import Logger from '../common/utils/Logger';
import PreferenceUtil from '../common/utils/PreferenceUtil';
import { hasNet } from '../common/utils/HttpUtil';
import { DownloadState } from '../common/constants/CommonConstants';

export default class AppAbilityStage extends AbilityStage {
    onCreate(): void {
        Logger.info('AppAbilityStage', 'onCreate');
        PreferenceUtil.loadPreference(this.context)
        // 初始化 AppStorage ，避免出现undefined
        AppStorage.setOrCreate('downloadState', DownloadState.NONE)  //当前应用状态
        AppStorage.setOrCreate('progress', 0)  //当前下载进度百分比
        AppStorage.setOrCreate('receivedSize', 0)  //当前文件已下载的大小
        AppStorage.setOrCreate('totalSize', -1)  //当前下载文件总大小
        AppStorage.setOrCreate('netAvailable', hasNet())  //网络是否可用
        AppStorage.setOrCreate('isBackground', true)  //应用是否在后台，用于控制是否弹窗
    }
}
